package com.mofang.powerdekorhelper.persenter;

import com.mofang.powerdekorhelper.base.BasePresent;
import com.mofang.powerdekorhelper.model.CustomerActivityDetail;
import com.mofang.powerdekorhelper.utils.Constants;
import com.mofang.powerdekorhelper.utils.UrlTools;
import com.mofang.powerdekorhelper.utils.http.InitRetrofit;
import com.mofang.powerdekorhelper.utils.http.RetrofitSerives;
import com.mofang.powerdekorhelper.view.CustomerActivityDetailView;

import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by luofei on 2017/9/2 0002.
 * 说明：
 */

public class CustomerActivityDetailPersenter extends BasePresent<CustomerActivityDetailView> {

    RetrofitSerives retrofitSerives;
    Call<CustomerActivityDetail> activityDetailCall;

    public void getActivityDetail(String jsonParams) {

        view.showProgress();
        retrofitSerives = InitRetrofit.getInstance().getRetrofit(UrlTools.Services);
        RequestBody body = RequestBody.create(okhttp3.MediaType.parse("application/json; charset=utf-8"), jsonParams);
        activityDetailCall = retrofitSerives.getCustomerActivityDetail(body);
        activityDetailCall.enqueue(new Callback<CustomerActivityDetail>() {
            @Override
            public void onResponse(Call<CustomerActivityDetail> call, Response<CustomerActivityDetail> response) {

                if (response.isSuccessful()) {
                    if (response.body().getCode().equals("0")) {
                        view.setCustomerActivityDetail(response.body());
                    } else {
                        view.onError(Constants.REQUEST_ERROR_INFO);
                    }
                } else {
                    view.onError(Constants.REQUEST_ERROR_INFO);
                }
            }

            @Override
            public void onFailure(Call<CustomerActivityDetail> call, Throwable t) {
                view.onError(Constants.REQUEST_ERROR_INFO);
            }
        });
    }

    @Override
    public void stopRequest() {

    }
}
